6

Beginner’s Guide to Code Algorithms

6

These four qualities can be easily understood with the recipe example.

The recipe is accurate, in the sense that it can create tasty chocolate chip cookies.

Note the emphasis on “tasty”. The recipe does not create “healthy” cookies. For that

matter, the word “healthy” has its own set of attributes, which are somewhat sub­

jective (does healthy mean less carb? More protein? Less cholesterol? More vita­

mins?) and mutually interdependent (higher magnesium and phosphorus in a readily

available ingredient like brown sugar may also mean higher carb).

Repeatable is easily demonstrated by being able to use the recipe again and again

for making delicious cookies. A recipe would not be so repeatable if it requires an

ingredient that is tough to procure. Or sometimes the product is self-​destructive,

which does not make it repeatable. A good example of a self-​destructive algorithm is

a video shoot of an accident.

Concise is a quality of being able to express in a few words. For example, I want

to say that I suffer from a problem where my lens in my right eye is unable to focus

light beyond a distance in front of my retina. I can express it with the term “myopia”.

While this is just a better way to communicate in this instance, for an algorithm that

is concise, it can have a huge consequence, such as reduce the cost of producing a

vaccine by 50% or increase the chances striking oil in the ground by 30%.

How to make chocolate chip cookies

Ingredients

-​ 2 cups all-​purpose flour

-​ 1 teaspoon baking soda

-​ Fine salt

-​ 1 stick (12 tablespoons) unsalted butter, at room temperature

-​ 1 cup packed light brown sugar

-​ 1 cup granulated sugar

-​ 2 large eggs

-​ 1 teaspoon pure vanilla extract

-​ One 12-​ounce bag semisweet chocolate chips

Process

1.  Preheat to 375 degrees F

2.  Stir together the flour, baking soda, and 1 teaspoon salt in a large bowl.

3.  Beat the butter and both sugars, eggs, vanilla, and flour about 4 minutes. Stir in the

chocolate chips.

4.  Scoop 12 tablespoons of dough about 2 inches apart onto each prepared baking sheet.

Roll the dough into balls with slightly wet hands.

5.  Bake, rotating the cookie sheets from upper to lower racks halfway through, until

golden but still soft in the center, 12 to 15 minutes.

6.  Wait for a few minutes on the baking sheet, and then transfer to a rack to cool

completely.

FIGURE 1.1  Making chocolate chip cookies.